import java.util.Scanner;

public class TestDay25 {
    //树根
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            String n =scanner.nextLine();
            while (n.length()!=1){
                int sum = 0;
                for(int i = 0;i < n.length(); i++){
                    char c = n.charAt(i);
                    sum+=c-'0';
                }
                n = String.valueOf(sum);

            }
            System.out.println(n);

        }
    }
    //星际密码
    public static void main1(String[] agrs){
        int[]array = new int[10001];
        array[1] = 1;
        array[2] = 2;
        for(int i = 3;i<array.length;i++){
            array[i] = array[i-1]+array[i-2];
            array[i] %= 10000;
        }
        Scanner scanner = new Scanner(System.in);

        while(scanner.hasNext()){
            StringBuilder str = new StringBuilder();
            int n =scanner.nextInt();
            for(int i = 0;i < n; i++){
                str.append(String.format("%04d",array[scanner.nextInt()]));

            }
            System.out.println(str);

        }


    }
}
